﻿using AdminStyem.Application.Command.CultivationCommand;
using AdminStyem.Application.DTO;
using AdminStyem.Domain.Entity.Boss;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.CultivatioHandler
{
    public class BreedingShowCommandHandler : IRequestHandler<BreedingShowCommand, APIResult<List<BreedBassesDTO>>>
    {
        IBaseRespository<BreedBass> BaseBreed;

        public BreedingShowCommandHandler(IBaseRespository<BreedBass> baseBreed)
        {
            BaseBreed = baseBreed;
        }

        public async Task<APIResult<List<BreedBassesDTO>>> Handle(BreedingShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<BreedBassesDTO>> ret = new APIResult<List<BreedBassesDTO>>();
            var breedBasses = await BaseBreed.GetAll();
            var breedBassesDTOs = breedBasses.Select(b => new BreedBassesDTO
            {
                BreedBassId = b.BreedBassId,
                Farms = b.Farms,
                Head = b.Head,
                QuantityNum = b.QuantityNum,
                BreedPhoto = b.BreedPhoto
            }).ToList();

            ret.Code = ResultCode.查询成功;
            ret.Message = ResultCode.查询成功.ToString();
            ret.Data = breedBassesDTOs;

            return ret;
        }
    }
}
